Skip to content

feat(execution): persist engine runs + tool calls via ExecutionStore#7

Draft
aryasaatvik wants to merge 1 commit intofeat/sdk-execution-store-adapterfrom
feat/execution-engine-persistence
Draft

feat(execution): persist engine runs + tool calls via ExecutionStore#7
aryasaatvik wants to merge 1 commit intofeat/sdk-execution-store-adapterfrom
feat/execution-engine-persistence

Conversation

@aryasaatvik
Copy link
Copy Markdown
Owner

Stacked review copy of upstream RhysSullivan#398 · stacked on #5.

Prev: feat/sdk-execution-store-adapter (#5)
Next: feat/trigger-propagation-cli-mcp


See upstream PR #398 for full description.

Wires `executor.executions` into the Effect-native engine so every
`execute()` / `executeWithPause()` / `resume()` call writes an
`execution` row and its associated tool-call + interaction rows to
whichever `DBAdapter` backs the SDK.

Engine additions:
- `ExecutionTrigger` type + new `trigger?` option on `execute` and
  `executeWithPause`. Callers attribute runs ("cli", "http", "mcp",
  …); the kind + optional meta blob are persisted on the row.
- A stable `crypto.randomUUID()` execution id is minted at entry and
  reused as `PausedExecution.id`, so callers and the DB share the
  same identifier and counts line up across pause/resume.
- `makeRecordingInvoker` wraps the `SandboxToolInvoker` passed to the
  code executor; each `invoke` writes a tool-call row (running →
  completed|failed with duration). Storage errors are ignored so
  bookkeeping failures can never fail the tool call itself.
- `persistTerminalState` runs once on fiber success or failure and
  writes final status, result/error, logs, toolCallCount, completedAt.
- Pausable path: on elicitation, the execution transitions to
  `waiting_for_interaction` and a pending interaction row is created;
  `resume` resolves it (or cancels it if action === "cancel") before
  unblocking the fiber. A `toolCallCounters` map keeps the same Ref
  across pause/resume so the final count is accurate.
- Inline path: wraps the caller-supplied `onElicitation` so every
  inline elicitation gets the same pending → resolved bookkeeping.

Tests (`engine-persistence.test.ts`, 5 cases) cover:
- completed run + tool call rows
- error result → status=failed, errorText captured
- toolCallCount rolls up correctly
- trigger kind + meta persist on the row
- failed tool call records status=failed with errorText
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant